#!/bin/bash
echo -e  "\e[32m=======开始安装redis========\e[0m"
if ! docker images | grep "redis.*latest.*" &>/dev/null
then
	
	echo -e  "\e[33m=======开始拉取redis镜像========\e[0m"
	docker pull redis
	echo -e  "\e[33m=======镜像拉取完成========\e[0m"
fi
if docker ps -a | grep "redis$" &>/dev/null
then
	docker rm -f  redis &>/dev/null
fi
mkdir -p /mydata/redis/conf
touch /mydata/redis/conf/redis.conf

docker run -p 6379:6379 --name=redis --restart=always \
-v /mydata/redis/conf/redis.conf:/etc/redis/redis.conf \
-v /mydata/redis/data:/data \
-d redis redis-server /etc/redis/redis.conf >/dev/null

cat >/mydata/redis/conf/redis.conf << EOF
appendonly  yes
EOF
docker restart redis>/dev/null
echo -e "\e[32m======redis安装完成========\e[0m"
